package znyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import znyl.common.annotation.Log;
import znyl.common.core.controller.BaseController;
import znyl.common.core.domain.AjaxResult;
import znyl.common.core.domain.R;
import znyl.common.enums.BusinessType;
import znyl.nursing.domain.Room;
import znyl.nursing.service.IRoomService;
import znyl.common.utils.poi.ExcelUtil;
import znyl.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import znyl.nursing.vo.RoomVo;

/**
 * 房间Controller
 * 
 * @author 睢高浩
 * @date 2025-11-05
 */
@Api(tags =  "房间相关接口")
@RestController
@RequestMapping("/elder/room")
public class RoomController extends BaseController
{
    @Autowired
    private IRoomService roomService;

    /**
     * 查询房间列表
     */
    @ApiOperation(value = "查询房间列表")
    @PreAuthorize("@ss.hasPermi('elder:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(Room room)
    {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }

    /**
     * 导出房间列表
     */
    @ApiOperation(value = "导出房间列表")
    @PreAuthorize("@ss.hasPermi('elder:room:export')")
    @Log(title = "房间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Room room)
    {
        List<Room> list = roomService.selectRoomList(room);
        ExcelUtil<Room> util = new ExcelUtil<Room>(Room.class);
        util.exportExcel(response, list, "房间数据");
    }

    /**
     * 获取房间详细信息
     */
    @ApiOperation(value = "获取房间详细信息")
    @PreAuthorize("@ss.hasPermi('elder:room:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(value = "房间ID", required = true)
                                  @PathVariable("id") Long id)
    {
        return success(roomService.selectRoomById(id));
    }

    /**
     * 新增房间
     */
    @PreAuthorize("@ss.hasPermi('elder:room:add')")
    @Log(title = "房间", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增房间")
    public AjaxResult add(@ApiParam(value = "房间实体", required = true) @RequestBody Room room)
    {
        return toAjax(roomService.insertRoom(room));
    }

    /**
     * 修改房间
     */

    @PreAuthorize("@ss.hasPermi('elder:room:edit')")
    @Log(title = "房间", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改房间")
    public AjaxResult edit(@ApiParam(value = "房间实体", required = true)  @RequestBody Room room) {
        {
            return toAjax(roomService.updateRoom(room));
        }
    }
    /**
     * 删除房间
     */
    @ApiOperation(value = "删除房间")
    @PreAuthorize("@ss.hasPermi('elder:room:remove')")
    @Log(title = "房间", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(roomService.deleteRoomByIds(ids));
    }
    /**
     * 查询房间数据
     */
    @ApiOperation(value = "查询房间数据")
    @GetMapping("/one/{id}")
    public R one(@ApiParam(value = "房间ID", required = true) @PathVariable("id") Long id) {
        RoomVo roomVo = roomService.getRoomById(id);
        return R.ok(roomVo);

    }
}
